package com.ruoyi.web.controller.weiriya;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.WVehicle;
import com.ruoyi.weiriya.service.IWVehicleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 车辆信息Controller
 * 
 * @author lynn
 * @date 2023-08-01
 */
@Api(tags = "车辆信息管理")
@RestController
@RequestMapping("/weiriya/vehicle")
public class WVehicleController extends BaseController
{
    @Autowired
    private IWVehicleService wVehicleService;

    /**
     * 查询车辆信息列表
     */
    @ApiOperation("获取车辆信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(WVehicle wVehicle)
    {
        startPage();
        List<WVehicle> list = wVehicleService.getList(wVehicle);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @ApiOperation("导出车辆信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:export')")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WVehicle wVehicle)
    {
        List<WVehicle> list = wVehicleService.getList(wVehicle);
        ExcelUtil<WVehicle> util = new ExcelUtil<WVehicle>(WVehicle.class);
        util.exportExcel(response, list, "车辆信息数据");
    }

    /**
     * 导入车辆信息列表
     */
    @ApiOperation("导入车辆信息列表")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:import')")
    @Log(title = "车辆信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WVehicle> util = new ExcelUtil<WVehicle>(WVehicle.class);
        List<WVehicle> list = util.importExcel(file.getInputStream());
        return success(wVehicleService.saveBatch(list));
    }

    /**
     * 获取车辆信息详细信息
     */
    @ApiOperation("获取车辆信息详细")
    @ApiImplicitParam(name = "id", value = "车辆信息ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wVehicleService.getWVehicleById(id));
    }

    /**
     * 获取车辆信息详细信息
     */
    @ApiOperation("获取车辆信息详细")
    @ApiImplicitParam(name = "memberId", value = "用户ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:query')")
    @GetMapping(value = "/getByMemberId/{memberId}")
    public AjaxResult getByMemberId(@PathVariable(value = "memberId") String memberId)
    {
        return success(wVehicleService.getWVehicleByMemberId(memberId));
    }
    /**
     * 获取车辆信息详细信息
     */
    @ApiOperation("获取车辆信息详细")
    @ApiImplicitParam(name = "memberId", value = "用户ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:query')")
    @GetMapping(value = {"/getByMember"})
    public AjaxResult getByMember()
    {
        return success(wVehicleService.getWVehicleByMemberId(SecurityUtils.getUserId().toString()));
    }

    /**
     * 新增车辆信息
     */
    @ApiOperation("新增车辆信息")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:add')")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WVehicle wVehicle)
    {
        return toAjax(wVehicleService.saveWVehicle(wVehicle));
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation("更新车辆信息")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:edit')")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WVehicle wVehicle)
    {
        return toAjax(wVehicleService.updateWVehicleById(wVehicle));
    }

    /**
     * 删除车辆信息
     */
    @ApiOperation("删除车辆信息")
    @ApiImplicitParam(name = "ids", value = "车辆信息ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:vehicle:remove')")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wVehicleService.removeByIds(ids));
    }
}
